import * as types from './actionTypes';

const defaultState = {
    inputValue: '52354',
    list: ["asd","asda","1"]
};

export default (state = defaultState, action) => {
    if (action.type === types.HANDLE_INPUT_VALUE) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        return newState;
    }

    if (action.type === types.ADD_LIST_ITEM) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.list.push(state.inputValue);
        newState.inputValue = '';
        return newState;
    }

    if (action.type === types.DELETE_LIST_ITEM) {
        let newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.index,1);
        return newState;
    }
    return state;
};